var e = require("../../../api.js"), t = getApp();

require("../../../utils/function.js");

Page({
    data: {
        typeIdx: 0,
        detail: {},
        invoiceType: [],
        headType: [ 0, 1 ],
        headTypeIdx: 0,
        isTip: !0,
        bank: "",
        bank_account: "",
        dues_number: "",
        head_name: "",
        register_address: "",
        register_phone: "",
        remark: ""
    },
    onLoad: function(e) {
        this.getConfig();
    },
    onShow: function() {},
    changeHead: function(e) {
        var t = e.currentTarget.dataset.idx;
        this.setData({
            headTypeIdx: t
        });
    },
    changTab: function(e) {
        var t = e.currentTarget.dataset.idx, a = this.data.detail.warm_tips;
        1 == t && this.data.isTip && (wx.showModal({
            title: "温馨提示",
            content: "开发票金额在" + a + "以上可申请纸质发票，电子发票与纸质发票具有相同法律效应",
            showCancel: !1
        }), this.data.isTip = !1), this.setData({
            typeIdx: t
        });
    },
    setValue: function(e) {
        var t = {};
        t[e.currentTarget.dataset.type] = e.detail.value, this.setData(t);
    },
    getConfig: function() {
        var a = this;
        this.setData({
            orders: wx.getStorageSync("INVOICE_DETAIL")
        }), t.request({
            url: e.default.invoice,
            method: "post",
            data: {},
            success: function(e) {
                if (1 == e.code) {
                    var t = e.data, n = [];
                    if (1 == t.open_auto_invoice) {
                        var i = {};
                        i.title = "电子发票", i.type = 0, i.spec = t.auto_time_des, n.push(i);
                    }
                    if (1 == t.open_manul_invoice) {
                        var o = {};
                        o.title = "纸质发票", o.type = 1, o.spec = t.manual_time_des, n.push(o);
                    }
                    a.setData({
                        detail: t,
                        invoiceType: n
                    });
                }
            }
        });
    },
    submit: function() {
        var a = this.getForm();
        return console.log(a), "" == a.head_name || 0 == a.head_type && "" == a.dues_number ? (wx.showToast({
            title: "请填写发票信息1",
            icon: "none"
        }), !1) : 0 == a.type && "" == a.mail ? (wx.showToast({
            title: "请填写发票信息2",
            icon: "none"
        }), !1) : 1 != a.type || "" != a.address && "" != a.phone ? void t.request({
            url: e.user.inoviceApply,
            method: "post",
            data: a,
            success: function(e) {
                wx.showToast({
                    title: e.msg,
                    icon: "none"
                }), 1 == e.code && (wx.removeStorageSync("INVOICE_DETAIL"), setTimeout(function() {
                    wx.navigateBack();
                }, 800));
            }
        }) : (wx.showToast({
            title: "请填写发票信息3",
            icon: "none"
        }), !1);
    },
    getForm: function() {
        var e = this.data;
        return {
            type: e.invoiceType[e.typeIdx].type || "",
            head_type: e.headTypeIdx || "",
            head_name: e.head_name || "",
            dues_number: e.dues_number || "",
            register_address: e.register_address || "",
            register_phone: e.register_phone || "",
            phone: e.phone || "",
            address: e.address || "",
            mail: e.mail || "",
            bank: e.bank || "",
            bank_account: e.bank_account || "",
            price: e.orders.price,
            content: e.detail.content || "",
            orders: e.orders.orderLists,
            remark: e.remark || ""
        };
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});